<?php
namespace x\my;
use Yansongda\Pay\Pay as Pays;

class Pay {
	/**
	 * 微信支付
	 * @param  array  $config [微信配置]
	 * @return [type]         [description]
	 */
	public static function wechat($config = []) {
		$default = [
			'appid' => '', // APP APPID
			'app_id' => '', // 公众号 APPID
			'miniapp_id' => '', // 小程序 APPID
			'mch_id' => '', // 支付平台 商户号
			'key' => '', // 支付平台 商户号 设置的key
			'notify_url' => '',
			'cert_client' => './cert/apiclient_cert.pem', // optional，退款等情况时用到
			'cert_key' => './cert/apiclient_key.pem', // optional，退款等情况时用到
			'log' => [ // optional
				'file' => APP_PATH . '../public/uploads/logs/wechat.log',
				'level' => 'debug',
			],
			'mode' => 'dev', // optional, dev/hk;当为 `hk` 时，为香港 gateway。
		];
		$config = array_merge($default, $config);
		return Pays::wechat($config);
	}
	/**
	 * 阿里支付
	 * @param  array  $config [支付宝配置]
	 * @return [type]         [description]
	 */
	public static function alipay($config = []) {
		$default = [
			'app_id' => '2016082000295641',
			'notify_url' => 'http://yansongda.cn/notify.php',
			'return_url' => 'http://yansongda.cn/return.php',
			'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWJKrQ6SWvS6niI+4vEVZiYfjkCfLQfoFI2nCp9ZLDS42QtiL4Ccyx8scgc3nhVwmVRte8f57TFvGhvJD0upT4O5O/lRxmTjechXAorirVdAODpOu0mFfQV9y/T9o9hHnU+VmO5spoVb3umqpq6D/Pt8p25Yk852/w01VTIczrXC4QlrbOEe3sr1E9auoC7rgYjjCO6lZUIDjX/oBmNXZxhRDrYx4Yf5X7y8FRBFvygIE2FgxV4Yw+SL3QAa2m5MLcbusJpxOml9YVQfP8iSurx41PvvXUMo49JG3BDVernaCYXQCoUJv9fJwbnfZd7J5YByC+5KM4sblJTq7bXZWQIDAQAB',
			// 加密方式： **RSA2**
			'private_key' => 'MIIEpAIBAAKCAQEAs6+F2leOgOrvj9jTeDhb5q46GewOjqLBlGSs/bVL4Z3fMr3p+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BMsHYPkcLehM1FmLZk1Q+ljcx3P1A/ds3kWXLolTXCrlpvNMBSN5NwOKAyhdPK/qkvnUrfX8sJ5XK2H4J8ECgYAGIZ0HIiE0Y+g9eJnpUFelXvsCEUW9YNK4065SD/BBGedmPHRC3OLgbo8X5A9BNEf6vP7fwpIiRfKhcjqqzOuk6fueA/yvYD04v+Da2MzzoS8+hkcqF3T3pta4I4tORRdRfCUzD80zTSZlRc/h286Y2eTETd+By1onnFFe2X01mwKBgQDaxo4PBcLL2OyVT5DoXiIdTCJ8KNZL9+kV1aiBuOWxnRgkDjPngslzNa1bK+klGgJNYDbQqohKNn1HeFX3mYNfCUpuSnD2Yag53Dd/1DLO+NxzwvTu4D6DCUnMMMBVaF42ig31Bs0jI3JQZVqeeFzSET8fkoFopJf3G6UXlrIEAQ==',
			'log' => [
				'file' => APP_PATH . '../public/uploads/logs/alipay.log',
				'level' => 'debug',
			],
			'mode' => 'dev', // optional,设置此参数，将进入沙箱模式
		];
		$config = array_merge($default, $config);
		return Pays::alipay($config);
	}

	//签名
	public static function sign($data, $key = '') {
		if (isset($data['sign'])) {
			unset($data['sign']);
		}

		$temp_k = array_keys($data);
		sort($temp_k);
		$str = "";
		foreach ($temp_k as $k) {
			if (isset($data[$k]) && is_string($data[$k])) {
				$str .= $k . "=" . $data[$k] . "&";
			}

		}
		$key = $key ? $key : c('api.wx_app_key');
		$str .= "key=" . $key;
		return strtoupper(MD5($str));
	}
}
